import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import axios from 'axios'
export default new Vuex.Store({

  state: {
    list: []
  },
  getters: {

  },
  mutations: {
    fs (state, res) {
      state.list = res
    },
    fn (state, id) {
      state.list = state.list.filter(item => item.id != id)
    }
  },
  actions: {
    async getList (aa) {
      let res = await axios.get('http://ajax-api.itheima.net/api/books')
      // console.log(res.data.data)
      // state.list = res.data.data
      aa.commit('fs', res.data.data)
    },
    async fn (id) {
      const res = await axios.delete('http://ajax-api.itheima.net/api/books/' + id)
      bb.commit('fn', id)

    },

  },
  modules: {

  }
})
